package easy

import "workspace/node"

func IsSubtree(root *node.TreeNode, subRoot *node.TreeNode) bool {
	if root == nil {
		return false
	}
	return check(root, subRoot) || IsSubtree(root.Left, subRoot) || IsSubtree(root.Right, subRoot)
}
func check(a, b *node.TreeNode) bool {
	if a == nil && b == nil {
		return true
	}
	if a == nil || b == nil {
		return false
	}
	if a.Val == b.Val {
		return check(a.Left, b.Left) && check(a.Right, b.Right)
	}
	return false
}
